//开始流程(gzlid工作流id，djid单据id，wgs网关数组，func回调函数)
function gzl_kslc(gzlid,djid,wgs,func){
    ycWindow.plugins.WorkFlow.getStartNode(gzlid, (node) => {
        debugger
        if (!node.start || !node.next) {
          if(fails){
            fails("获取开始节点失败")
          }else{
            ycWindow.dom.opener.dom.showMsg("获取开始节点失败", "error")
          }
        } else {
            // 开始流程的时候instance_id为空字符串
            const task = new ycWindow.plugins.Task("tq", {service: "workflow", method: "start", params: {"template_id": gzlid, "data_id": djid, "instance_id": "", "node_id": node.start, "next_node_id": node.next,"next_node_name": node.nextName}}, (res) => {
                debugger
                ycWindow.plugins.WorkFlow.getNextNode(djid, wgs, (next) => {
                  if (next === null) {
                    if(fails){
                      fails("获取下个节点失败")
                    }else{
                      ycWindow.dom.opener.dom.showMsg("获取下个节点失败", "error")
                    }
                  } else {
                      const task2 = new ycWindow.plugins.Task("tq", {service: "workflow", method: "next", params: {"template_id": next.work_flow_id, "data_id": djid, "instance_id": next.instance, "node_id": next.id, "next_node_id": next.nextId, "status": next.name, "next_node_name": next.nextName}}, (res) => {
                          debugger
                          func();
                      })
                      task2.start()
                  }
              })
            })
            task.start()
        }
    })
  }
  //下一步流程
  function gzl_xyb(djid,wgs,func){
    ycWindow.plugins.WorkFlow.getNextNode(djid, wgs, (next) => {
        if (next === null) {
          if(fails){
            fails("获取下个节点失败")
          }else{
            ycWindow.dom.opener.dom.showMsg("获取下个节点失败", "error")
          }
        } else {
            const task = new ycWindow.plugins.Task("tq", {service: "workflow", method: "next", params: {"template_id": next.work_flow_id, "data_id": djid, "instance_id": next.instance, "node_id": next.id, "next_node_id": next.nextId, "status": next.name, "next_node_name": next.nextName}}, (res) => {
                debugger
                res["next_name"]=next.name;
                func(res,next);
            })
            task.start()
        }
    })
  }
  //获取下一步流程
  function gzl_hqxyb(djid,wgs,func){
    debugger
    ycWindow.plugins.WorkFlow.getNextNode(djid, wgs, (next) => {
        debugger
        if (next === null) {
          if(fails){
            fails("获取下个节点失败")
          }else{
            ycWindow.dom.opener.dom.showMsg("获取下个节点失败", "error")
          }
        } else {
            var res={};
            res["next_name"]=next.nextName;
            func(res,next);
        }
    })
  }
  //执行下一步工作流任务
  function gzl_zxxyb(next,djid,func){
    const task = new ycWindow.plugins.Task("tq", {service: "workflow", method: "next", params: {"template_id": next.work_flow_id, "data_id": djid, "instance_id": next.instance, "node_id": next.id, "next_node_id": next.nextId, "status": next.name, "next_node_name": next.nextName}}, (res) => {
        func();
    })
    task.start()
  }
  //查询单据流程(djid单据id，func回调函数)
  function gzl_cxdjlc(djid,func){
    //查询单据流程
    ycWindow.plugins.WorkFlow.getStatus(djid, (res) => {
        func(res);
    }, () => {
      if(fails){
        fails("获取状态失败")
      }else{
        ycWindow.dom.opener.dom.showMsg("获取状态失败", "error")
      }
    })
  }
  //查询步骤执行人信息(dataId单据id，ztmc状态名称，func回调函数)
  function gzl_bzzxr(dataId,ztmc,func){
    debugger
    const args = {
      "datatable_id": "1924683377768665088",//工作流步骤
      "search": "",
      "search_fields": [
        {
          "quick_search": true,
          "field": "opt_user_id",
          "table": "a",
          "data_type": 1
        },
        {
          "quick_search": true,
          "field": "ifnull(c.:[bsc],'') as bsc",
          "table": "a",
          "data_type": 11
        }
      ],
      "query_orders": [],
      "advance_filters": {condition: "a.:[status]=? and b.:[data_id]=?", values: JSON.stringify([ztmc,dataId])},
      "order_by": "order by a.:[last_update_time] desc",//a.:[last_update_time] desc
      "group_by": "",
      "where": "",
      "join_tables": "left join dataset_store_workflow_instance b on a.:[workflow_instance_id] = b.id left join dataset_store_xt_yh c on a.:[opt_user_id] = c.id",
      "query_tables": "",
      "page": 1,
      "page_size": 20,
      "include": {} 
    }
    debugger
    ycWindow.plugins.crud.Query(args, (result) => {
      debugger
      var ryobj={"bsc":""};
      if(result.total){
        ryobj.bsc=result.data[0].bsc;
      }
      func(ryobj);
    }, (data) => {
    })
  }
  //获取工作流权限(mbid工作流模版id，lc流程名称)
  function glz_gzlqx(mbid,lc,func){
    var userinfo=ycWindow.plugins.userinfo();
    const args = {
      "datatable_id": "1949678332438122496",
      "search": "",
      "search_fields": [
      ],
      "advance_filters": {condition: "a.:[workflow_id]=? and a.:[workflow_step]=? and a.:[user_id]=?", values: JSON.stringify([mbid,lc,userinfo.user_id])},
      "page": 1,
      "page_size": 999999
    }
    debugger
    ycWindow.plugins.crud.Query(args, (result) => {
        debugger
      func(result.total)
    }, (data) => {
      if(fails){
        fails(data)
      }else{
        ycWindow.dom.opener.dom.showMsg(data, "error")
      }
    })
  }
  //获取工作流权限(mbid工作流模版id，lc流程名称，bsc办事处)
  function glz_gzlqx_plus(mbid,lc,bsc,func){
    var bsclc=["办事处确认","客户上传盖章保函文件"]
    var userinfo=ycWindow.plugins.userinfo();
    var args = {}
    //如果是办事处流程，则需要确认当前用户是否属于单据办事处的成员，如果不是则确认当前用户是否有流程权限
    if(bsclc.indexOf(lc)!=-1){
      args = {
        "datatable_id": "1876901282506084352",
        "search": "",
        "search_fields": [
        ],
        "advance_filters": {condition: "a.:[org_id]=? and a.id=?", values: JSON.stringify([bsc,userinfo.user_id])},
        "page": 1,
        "page_size": 999999
      }
    }else{
      args = {
        "datatable_id": "1949678332438122496",
        "search": "",
        "search_fields": [
        ],
        "advance_filters": {condition: "a.:[workflow_id]=? and a.:[workflow_step]=? and a.:[user_id]=?", values: JSON.stringify([mbid,lc,userinfo.user_id])},
        "page": 1,
        "page_size": 999999
      }
    }
    debugger
    ycWindow.plugins.crud.Query(args, (result) => {
        debugger
      func(result.total)
    }, (data) => {
      if(fails){
        fails(data)
      }else{
        ycWindow.dom.opener.dom.showMsg(data, "error")
      }
    })
  }
  //生成待办任务,自动查询下一步流程，不能用在开始流程(gzlid工作流id，djid单据id，wgs网关数组,yybh应用编号,sj时间,dqlc当前流程,userid用户id，yw业务，zzs终止流程,bt标题,spjz审批机制)
  function gzl_scdbrw(gzlid,djid,wgs,yybh,sj,dqlc,userid,yw,zzs,bt,spjz,func){
    debugger
    var userinfo=ycWindow.plugins.userinfo();
    var args1={"steps":[]}
    //获取下一步流程
    gzl_hqxyb(djid,wgs,(res,next)=>{
      debugger
        //下一步流程名称
        var next=res.next_name
        //获取流程节点有权限的用户
        const args = {
            "datatable_id": "1949678332438122496",
            "search": "",
            "search_fields": [
              {
                "quick_search": true,
                "field": "user_id",
                "table": "a",
                "data_type": 1
              }
            ],
            "advance_filters": {condition: "a.:[workflow_id]=? and a.:[workflow_step]=?", values: JSON.stringify([gzlid,next])},
            "join_tables": "",
            "page": 1,
            "page_size": 999999,
            "include": {} 
          }
          ycWindow.plugins.crud.Query(args, (result) => {
            debugger
            if(spjz=="全部同意通过"){
              //查询出当前单据当前流程的所有待办任务
              const args = {
                "datatable_id": "1943259316018483200", // 数据源id
                "search_fields": [
                  {
                    "quick_search": true,
                    "field": "jsrbh",
                    "table": "a",
                    "data_type": 1
                  },
                  {
                    "quick_search": true,
                    "field": "zt",
                    "table": "a",
                    "data_type": 1
                  }
                ],
                "advance_filters": {condition: "a.:[glsjbh]=? and a.:[lc]=? and a.:[zt]!=?", values: JSON.stringify([djid,dqlc,"完成"])},
                "page": 1,
                "page_size": 999999,
                "include": {} 
              }
              ycWindow.plugins.crud.Query(args, (result2) => {
                debugger
                if(result2.total){
                  result2.data.forEach((item,index) => {
                    //判断待办任务接收人编号是否是当前用户，是则修改待办任务状态
                    if(item.jsrbh==userinfo.user_id){
                      args1.steps.push({
                        "step_name": "更新待办任务状态"+index,
                        "opt_type": 4,
                        "datatable_id": "1943259316018483200",
                        "args": item.id,
                        "args_from": 1,
                        "field_params": [
                          {
                            "value_from": 1,
                            "field": "zt",
                            "value": "完成",
                            "data_type": 1
                          }
                        ]
                      })
                      //如果待办任务接收人是当前用户，并且只剩一个待办任务，则生成新的待办任务
                      if(result2.total==1){
                        //有权限的用户总数不为零，并且下一步不是终止流程
                        if(result.total&&zzs.indexOf(next)==-1){
                          result.data.forEach((item,index) => {
                              //添加待办任务
                              args1.steps.push({
                                  "step_name": "添加待办任务"+index,
                                  "opt_type": 1,
                                  "datatable_id": "1943259316018483200",
                                  "args": "",
                                  "field_params": [{
                                      "value_from": 1,
                                      "field": "glsjbh",//单据编号
                                      "value": djid,
                                      "data_type": 1
                                  },{
                                      "value_from": 1,
                                      "field": "yybh",
                                      "value": yybh,//应用编号
                                      "data_type": 1
                                  },{
                                      "value_from": 1,
                                      "field": "jsrbh",
                                      "value": item.user_id,//接收人编号
                                      "data_type": 1
                                  },{
                                    "value_from": 1,
                                    "field": "fssj",
                                    "value": sj,//发送时间
                                    "data_type": 1
                                  },{
                                    "value_from": 1,
                                    "field": "lc",
                                    "value": next,//流程
                                    "data_type": 1
                                  },{
                                    "value_from": 1,
                                    "field": "yw",
                                    "value": yw,//业务
                                    "data_type": 1
                                  },{
                                      "value_from": 1,
                                      "field": "zt",
                                      "value": "待办理",//状态
                                      "data_type": 1
                                  },{
                                    "value_from": 1,
                                    "field": "bt",
                                    "value": bt,//标题
                                    "data_type": 1
                                }]
                              }) 
                          });
                      }else if(result.total==0&&zzs.indexOf(next)==-1){
                        if(fails){
                          fails("未设置办理人")
                        }else{
                          ycWindow.dom.showMsg("未设置办理人", "error")
                        }
                        return false
                      }
                      }
                    }
                  });
                }
                debugger
                if(args1.steps.length){
                  ycWindow.plugins.crud.ExecJobs(args1, (data) => {
                      //判断是否只剩一个未完成的待办任务，如果是则返回true
                      if(result2.total==1){
                        func(true)
                      }else{
                        func(false)
                      }
                    }, (data) => {
                      if(fails){
                        fails(data)
                      }else{
                        ycWindow.dom.showMsg(data, "error")
                      }
                  })
                }
              }, (data) => {
                if(fails){
                  fails(data)
                }else{
                  ycWindow.dom.showMsg(data, "error")
                }
              })
            }else{
              //有权限的用户总数不为零，并且下一步不是终止流程
              if(result.total&&zzs.indexOf(next)==-1){
                  result.data.forEach((item,index) => {
                      //添加待办任务
                      args1.steps.push({
                          "step_name": "添加待办任务"+index,
                          "opt_type": 1,
                          "datatable_id": "1943259316018483200",
                          "args": "",
                          "field_params": [{
                              "value_from": 1,
                              "field": "glsjbh",//单据编号
                              "value": djid,
                              "data_type": 1
                          },{
                              "value_from": 1,
                              "field": "yybh",
                              "value": yybh,//应用编号
                              "data_type": 1
                          },{
                              "value_from": 1,
                              "field": "jsrbh",
                              "value": item.user_id,//接收人编号
                              "data_type": 1
                          },{
                            "value_from": 1,
                            "field": "fssj",
                            "value": sj,//发送时间
                            "data_type": 1
                          },{
                            "value_from": 1,
                            "field": "lc",
                            "value": next,//流程
                            "data_type": 1
                          },{
                            "value_from": 1,
                            "field": "yw",
                            "value": yw,//业务
                            "data_type": 1
                          },{
                              "value_from": 1,
                              "field": "zt",
                              "value": "待办理",//状态
                              "data_type": 1
                          },{
                            "value_from": 1,
                            "field": "bt",
                            "value": bt,//标题
                            "data_type": 1
                        }]
                      }) 
                  });
              }else if(result.total==0&&zzs.indexOf(next)==-1){
                if(fails){
                  fails("未设置办理人")
                }else{
                  ycWindow.dom.showMsg("未设置办理人", "error")
                }
                return false
              }
              debugger
              //查询出当前单据当前流程的所有待办任务
              const args = {
                "datatable_id": "1943259316018483200", // 数据源id
                "search_fields": [
                  {
                    "quick_search": true,
                    "field": "jsrbh",
                    "table": "a",
                    "data_type": 1
                  }
                ],
                "advance_filters": {condition: "a.:[glsjbh]=? and a.:[lc]=?", values: JSON.stringify([djid,dqlc])},
                "page": 1,
                "page_size": 999999,
                "include": {} 
              }
              ycWindow.plugins.crud.Query(args, (result2) => {
                debugger
                if(result2.total){
                  result2.data.forEach((item,index) => {
                    args1.steps.push({
                      "step_name": "更新待办任务状态"+index,
                      "opt_type": 4,
                      "datatable_id": "1943259316018483200",
                      "args": item.id,
                      "args_from": 1,
                      "field_params": [
                        {
                          "value_from": 1,
                          "field": "zt",
                          "value": item.jsrbh==userid?"完成":"他人已办理",//判断是否是当前用户id，如果是则状态更新为完成，如果不是则为他人已办理
                          "data_type": 1
                        }
                      ]
                    })
                  });
                }
                debugger
                if(args1.steps.length){
                  ycWindow.plugins.crud.ExecJobs(args1, (data) => {
                      func(true)
                    }, (data) => {
                      if(fails){
                        fails(data)
                      }else{
                        ycWindow.dom.showMsg(data, "error")
                      }
                  })
                }
              }, (data) => {
                if(fails){
                  fails(data)
                }else{
                  ycWindow.dom.showMsg(data, "error")
                }
              })
            }
          }, (data) => {
            if(fails){
              fails(data)
            }else{
              ycWindow.dom.showMsg(data, "error")
            }
          })
    })
  }
  //生成待办任务,自动查询下一步流程，不能用在开始流程(gzlid工作流id，djid单据id，wgs网关数组,yybh应用编号,sj时间,dqlc当前流程,userid用户id，yw业务，zzs终止流程,bt标题,spjz审批机制,bsc办事处)
  function gzl_scdbrw_plus(gzlid,djid,wgs,yybh,sj,dqlc,userid,yw,zzs,bt,spjz,bsc,func){
    debugger
    //办事处流程节点
    var bsclcs=["办事处确认","客户上传盖章保函文件"]
    var userinfo=ycWindow.plugins.userinfo();
    var args1={"steps":[]}
    var args={}
    //获取下一步流程
    gzl_hqxyb(djid,wgs,(res,nextobj)=>{
      debugger
        //下一步流程名称
        var next=res.next_name
        //如果下一步流程是办事处流程，那么获取办事处下的所有用户
        if(bsclcs.indexOf(next)!=-1){
          //获取办事处用户
          args = {
            "datatable_id": "1876901282506084352",
            "search": "",
            "search_fields": [
              {
                "quick_search": true,
                "field": "ifnull(a.id,'') as user_id",
                "table": "",
                "data_type": 11
              }
            ],
            "advance_filters": {condition: "a.:[org_id]=?", values: JSON.stringify([bsc])},
            "join_tables": "",
            "page": 1,
            "page_size": 999999,
            "include": {} 
          }
        }else if(next.indexOf("提交")!=-1){//如果下一步流程是提交，则获取创建流程实例的用户（工作流步骤为开始）
          args = {
            "datatable_id": "1924683377768665088",
            "search": "",
            "search_fields": [
              {
                "quick_search": true,
                "field": "ifnull(a.:[opt_user_id],'') as user_id",
                "table": "",
                "data_type": 11
              }
            ],
            "advance_filters": {condition: "a.:[workflow_instance_id]=? and a.:[status]=?", values: JSON.stringify([nextobj.instance,"开始"])},
            "join_tables": "",
            "page": 1,
            "page_size": 999999,
            "include": {} 
          }
        }else{
          //获取流程节点有权限的用户
          args = {
            "datatable_id": "1949678332438122496",
            "search": "",
            "search_fields": [
              {
                "quick_search": true,
                "field": "user_id",
                "table": "a",
                "data_type": 1
              }
            ],
            "advance_filters": {condition: "a.:[workflow_id]=? and a.:[workflow_step]=?", values: JSON.stringify([gzlid,next])},
            "join_tables": "",
            "page": 1,
            "page_size": 999999,
            "include": {} 
          }
        }
          ycWindow.plugins.crud.Query(args, (result) => {
            debugger
            if(spjz=="全部同意通过"){
              //查询出当前单据当前流程的所有待办任务
              const args = {
                "datatable_id": "1943259316018483200", // 数据源id
                "search_fields": [
                  {
                    "quick_search": true,
                    "field": "jsrbh",
                    "table": "a",
                    "data_type": 1
                  },
                  {
                    "quick_search": true,
                    "field": "zt",
                    "table": "a",
                    "data_type": 1
                  }
                ],
                "advance_filters": {condition: "a.:[glsjbh]=? and a.:[lc]=? and a.:[zt]!=?", values: JSON.stringify([djid,dqlc,"完成"])},
                "page": 1,
                "page_size": 999999,
                "include": {} 
              }
              ycWindow.plugins.crud.Query(args, (result2) => {
                debugger
                if(result2.total){
                  result2.data.forEach((item,index) => {
                    //判断待办任务接收人编号是否是当前用户，是则修改待办任务状态
                    if(item.jsrbh==userinfo.user_id){
                      args1.steps.push({
                        "step_name": "更新待办任务状态"+index,
                        "opt_type": 4,
                        "datatable_id": "1943259316018483200",
                        "args": item.id,
                        "args_from": 1,
                        "field_params": [
                          {
                            "value_from": 1,
                            "field": "zt",
                            "value": "完成",
                            "data_type": 1
                          }
                        ]
                      })
                      //如果待办任务接收人是当前用户，并且只剩一个待办任务，则生成新的待办任务
                      if(result2.total==1){
                        //有权限的用户总数不为零，并且下一步不是终止流程
                        if(result.total&&zzs.indexOf(next)==-1){
                          result.data.forEach((item,index) => {
                              //添加待办任务
                              args1.steps.push({
                                  "step_name": "添加待办任务"+index,
                                  "opt_type": 1,
                                  "datatable_id": "1943259316018483200",
                                  "args": "",
                                  "field_params": [{
                                      "value_from": 1,
                                      "field": "glsjbh",//单据编号
                                      "value": djid,
                                      "data_type": 1
                                  },{
                                      "value_from": 1,
                                      "field": "yybh",
                                      "value": yybh,//应用编号
                                      "data_type": 1
                                  },{
                                      "value_from": 1,
                                      "field": "jsrbh",
                                      "value": item.user_id,//接收人编号
                                      "data_type": 1
                                  },{
                                    "value_from": 1,
                                    "field": "fssj",
                                    "value": sj,//发送时间
                                    "data_type": 1
                                  },{
                                    "value_from": 1,
                                    "field": "lc",
                                    "value": next,//流程
                                    "data_type": 1
                                  },{
                                    "value_from": 1,
                                    "field": "yw",
                                    "value": yw,//业务
                                    "data_type": 1
                                  },{
                                      "value_from": 1,
                                      "field": "zt",
                                      "value": "待办理",//状态
                                      "data_type": 1
                                  },{
                                    "value_from": 1,
                                    "field": "bt",
                                    "value": bt,//标题
                                    "data_type": 1
                                }]
                              }) 
                          });
                      }else if(result.total==0&&zzs.indexOf(next)==-1){
                        if(fails){
                          fails("未设置办理人")
                        }else{
                          ycWindow.dom.showMsg("未设置办理人", "error")
                        }
                        return false
                      }
                      }
                    }
                  });
                }
                debugger
                if(args1.steps.length){
                  ycWindow.plugins.crud.ExecJobs(args1, (data) => {
                      //判断是否只剩一个未完成的待办任务，如果是则返回true
                      if(result2.total==1){
                        func(true)
                      }else{
                        func(false)
                      }
                    }, (data) => {
                      if(fails){
                        fails(data)
                      }else{
                        ycWindow.dom.showMsg(data, "error")
                      }
                  })
                }
              }, (data) => {
                if(fails){
                  fails(data)
                }else{
                  ycWindow.dom.showMsg(data, "error")
                }
              })
            }else{
              //有权限的用户总数不为零，并且下一步不是终止流程
              if(result.total&&zzs.indexOf(next)==-1){
                  result.data.forEach((item,index) => {
                      //添加待办任务
                      args1.steps.push({
                          "step_name": "添加待办任务"+index,
                          "opt_type": 1,
                          "datatable_id": "1943259316018483200",
                          "args": "",
                          "field_params": [{
                              "value_from": 1,
                              "field": "glsjbh",//单据编号
                              "value": djid,
                              "data_type": 1
                          },{
                              "value_from": 1,
                              "field": "yybh",
                              "value": yybh,//应用编号
                              "data_type": 1
                          },{
                              "value_from": 1,
                              "field": "jsrbh",
                              "value": item.user_id,//接收人编号
                              "data_type": 1
                          },{
                            "value_from": 1,
                            "field": "fssj",
                            "value": sj,//发送时间
                            "data_type": 1
                          },{
                            "value_from": 1,
                            "field": "lc",
                            "value": next,//流程
                            "data_type": 1
                          },{
                            "value_from": 1,
                            "field": "yw",
                            "value": yw,//业务
                            "data_type": 1
                          },{
                              "value_from": 1,
                              "field": "zt",
                              "value": "待办理",//状态
                              "data_type": 1
                          },{
                            "value_from": 1,
                            "field": "bt",
                            "value": bt,//标题
                            "data_type": 1
                        }]
                      }) 
                  });
              }else if(result.total==0&&zzs.indexOf(next)==-1){
                if(fails){
                  fails("未设置办理人")
                }else{
                  ycWindow.dom.showMsg("未设置办理人", "error")
                }
                return false
              }
              debugger
              //查询出当前单据当前流程的所有待办任务
              const args = {
                "datatable_id": "1943259316018483200", // 数据源id
                "search_fields": [
                  {
                    "quick_search": true,
                    "field": "jsrbh",
                    "table": "a",
                    "data_type": 1
                  }
                ],
                "advance_filters": {condition: "a.:[glsjbh]=? and a.:[lc]=?", values: JSON.stringify([djid,dqlc])},
                "page": 1,
                "page_size": 999999,
                "include": {} 
              }
              ycWindow.plugins.crud.Query(args, (result2) => {
                debugger
                if(result2.total){
                  result2.data.forEach((item,index) => {
                    args1.steps.push({
                      "step_name": "更新待办任务状态"+index,
                      "opt_type": 4,
                      "datatable_id": "1943259316018483200",
                      "args": item.id,
                      "args_from": 1,
                      "field_params": [
                        {
                          "value_from": 1,
                          "field": "zt",
                          "value": item.jsrbh==userid?"完成":"他人已办理",//判断是否是当前用户id，如果是则状态更新为完成，如果不是则为他人已办理
                          "data_type": 1
                        }
                      ]
                    })
                  });
                }
                debugger
                if(args1.steps.length){
                  ycWindow.plugins.crud.ExecJobs(args1, (data) => {
                      func(true)
                    }, (data) => {
                      if(fails){
                        fails(data)
                      }else{
                        ycWindow.dom.showMsg(data, "error")
                      }
                  })
                }
              }, (data) => {
                if(fails){
                  fails(data)
                }else{
                  ycWindow.dom.showMsg(data, "error")
                }
              })
            }
          }, (data) => {
            if(fails){
              fails(data)
            }else{
              ycWindow.dom.showMsg(data, "error")
            }
          })
    })
  }
  //生成待办任务，下一步流程需要传参(gzlid工作流id，djid单据id，wgs网关数组,yybh应用编号,sj时间,dqlc当前流程,userid用户id，yw业务，next下一步流程，zzs终止流程,bt标题)
  function gzl_scdbrw_xyb(gzlid,djid,wgs,yybh,sj,dqlc,userid,yw,next,zzs,bt,func){
    var args1={"steps":[]}
    debugger
    //获取流程节点有权限的用户
    const args = {
      "datatable_id": "1949678332438122496",
      "search": "",
      "search_fields": [
        {
          "quick_search": true,
          "field": "user_id",
          "table": "a",
          "data_type": 1
        }
      ],
      "advance_filters": {condition: "a.:[workflow_id]=? and a.:[workflow_step]=?", values: JSON.stringify([gzlid,next])},
      "join_tables": "",
      "page": 1,
      "page_size": 999999,
      "include": {} 
    }
    ycWindow.plugins.crud.Query(args, (result) => {
      debugger
      //有权限的用户总数不为零，并且下一步不是终止流程
      if(result.total&&zzs.indexOf(next)==-1){
          result.data.forEach((item,index) => {
              //添加待办任务
              args1.steps.push({
                  "step_name": "添加待办任务"+index,
                  "opt_type": 1,
                  "datatable_id": "1943259316018483200",
                  "args": "",
                  "field_params": [{
                      "value_from": 1,
                      "field": "glsjbh",//单据编号
                      "value": djid,
                      "data_type": 1
                  },{
                      "value_from": 1,
                      "field": "yybh",
                      "value": yybh,//应用编号
                      "data_type": 1
                  },{
                      "value_from": 1,
                      "field": "jsrbh",
                      "value": item.user_id,//接收人编号
                      "data_type": 1
                  },{
                    "value_from": 1,
                    "field": "fssj",
                    "value": sj,//发送时间
                    "data_type": 1
                  },{
                    "value_from": 1,
                    "field": "lc",
                    "value": next,//流程
                    "data_type": 1
                  },{
                    "value_from": 1,
                    "field": "yw",
                    "value": yw,//业务
                    "data_type": 1
                  },{
                      "value_from": 1,
                      "field": "zt",
                      "value": "待办理",//状态
                      "data_type": 1
                  },{
                    "value_from": 1,
                    "field": "bt",
                    "value": bt,//标题
                    "data_type": 1
                }]
              }) 
          });
      }else if(result.total==0&&zzs.indexOf(next)==-1){
        if(fails){
          fails("未设置办理人")
        }else{
          ycWindow.dom.showMsg("未设置办理人", "error")
        }
        return false
      }
      debugger
      //查询出当前单据当前流程的所有待办任务
      const args = {
        "datatable_id": "1943259316018483200", // 数据源id
        "search_fields": [
          {
            "quick_search": true,
            "field": "jsrbh",
            "table": "a",
            "data_type": 1
          }
        ],
        "advance_filters": {condition: "a.:[glsjbh]=? and a.:[lc]=?", values: JSON.stringify([djid,dqlc])},
        "page": 1,
        "page_size": 999999,
        "include": {} 
      }
      ycWindow.plugins.crud.Query(args, (result2) => {
        debugger
        if(result2.total){
          result2.data.forEach((item,index) => {
            args1.steps.push({
              "step_name": "更新待办任务状态"+index,
              "opt_type": 4,
              "datatable_id": "1943259316018483200",
              "args": item.id,
              "args_from": 1,
              "field_params": [
                {
                  "value_from": 1,
                  "field": "zt",
                  "value": item.jsrbh==userid?"完成":"他人已办理",//判断是否是当前用户id，如果是则状态更新为完成，如果不是则为他人已办理
                  "data_type": 1
                }
              ]
            })
          });
        }
        debugger
        if(args1.steps.length){
          ycWindow.plugins.crud.ExecJobs(args1, (data) => {
              func()
            }, (data) => {
              if(fails){
                fails(data)
              }else{
                ycWindow.dom.showMsg(data, "error")
              }
          })
        }
      }, (data) => {
        if(fails){
          fails(data)
        }else{
          ycWindow.dom.showMsg(data, "error")
        }
      })
    }, (data) => {
      if(fails){
        fails(data)
      }else{
        ycWindow.dom.showMsg(data, "error")
      }
    })
  }
  //生成待办任务，下一步流程需要传参(gzlid工作流id，djid单据id，wgs网关数组,yybh应用编号,sj时间,dqlc当前流程,userid用户id，yw业务，next下一步流程，zzs终止流程,bt标题,bsc办事处)
  function gzl_scdbrw_xyb_plus(gzlid,djid,wgs,yybh,sj,dqlc,userid,yw,next,zzs,bt,bsc,func){
    var userinfo=ycWindow.plugins.userinfo();
    //办事处流程节点
    var bsclcs=["办事处确认","客户上传盖章保函文件"]
    var args1={"steps":[]}
    var args = {}
    debugger
    //如果下一步流程是办事处流程，那么获取办事处下的所有用户
    if(bsclcs.indexOf(next)!=-1){
      //获取办事处用户
      args = {
        "datatable_id": "1876901282506084352",
        "search": "",
        "search_fields": [
          {
            "quick_search": true,
            "field": "ifnull(a.id,'') as user_id",
            "table": "",
            "data_type": 11
          }
        ],
        "advance_filters": {condition: "a.:[org_id]=?", values: JSON.stringify([bsc])},
        "join_tables": "",
        "page": 1,
        "page_size": 999999,
        "include": {} 
      }
    }else{
      //获取流程节点有权限的用户
      args = {
        "datatable_id": "1949678332438122496",
        "search": "",
        "search_fields": [
          {
            "quick_search": true,
            "field": "user_id",
            "table": "a",
            "data_type": 1
          }
        ],
        "advance_filters": {condition: "a.:[workflow_id]=? and a.:[workflow_step]=?", values: JSON.stringify([gzlid,next])},
        "join_tables": "",
        "page": 1,
        "page_size": 999999,
        "include": {} 
      }
    }
    debugger
    ycWindow.plugins.crud.Query(args, (result) => {
      debugger
      //有权限的用户总数不为零，并且下一步不是终止流程
      if(result.total&&zzs.indexOf(next)==-1){
          result.data.forEach((item,index) => {
              //添加待办任务
              args1.steps.push({
                  "step_name": "添加待办任务"+index,
                  "opt_type": 1,
                  "datatable_id": "1943259316018483200",
                  "args": "",
                  "field_params": [{
                      "value_from": 1,
                      "field": "glsjbh",//单据编号
                      "value": djid,
                      "data_type": 1
                  },{
                      "value_from": 1,
                      "field": "yybh",
                      "value": yybh,//应用编号
                      "data_type": 1
                  },{
                      "value_from": 1,
                      "field": "jsrbh",
                      "value": item.user_id,//接收人编号
                      "data_type": 1
                  },{
                    "value_from": 1,
                    "field": "fssj",
                    "value": sj,//发送时间
                    "data_type": 1
                  },{
                    "value_from": 1,
                    "field": "lc",
                    "value": next,//流程
                    "data_type": 1
                  },{
                    "value_from": 1,
                    "field": "yw",
                    "value": yw,//业务
                    "data_type": 1
                  },{
                      "value_from": 1,
                      "field": "zt",
                      "value": "待办理",//状态
                      "data_type": 1
                  },{
                    "value_from": 1,
                    "field": "bt",
                    "value": bt,//标题
                    "data_type": 1
                }]
              }) 
          });
          //添加提交用户已完成待办任务
          args1.steps.push({
            "step_name": "添加提交待办任务",
            "opt_type": 1,
            "datatable_id": "1943259316018483200",
            "args": "",
            "field_params": [{
                "value_from": 1,
                "field": "glsjbh",//单据编号
                "value": djid,
                "data_type": 1
            },{
                "value_from": 1,
                "field": "yybh",
                "value": yybh,//应用编号
                "data_type": 1
            },{
                "value_from": 1,
                "field": "jsrbh",
                "value": userinfo.user_id,//接收人编号
                "data_type": 1
            },{
              "value_from": 1,
              "field": "fssj",
              "value": sj,//发送时间
              "data_type": 1
            },{
              "value_from": 1,
              "field": "lc",
              "value": "提交",//流程
              "data_type": 1
            },{
              "value_from": 1,
              "field": "yw",
              "value": yw,//业务
              "data_type": 1
            },{
                "value_from": 1,
                "field": "zt",
                "value": "完成",//状态
                "data_type": 1
            },{
              "value_from": 1,
              "field": "bt",
              "value": bt,//标题
              "data_type": 1
          }]
        }) 
      }else if(result.total==0&&zzs.indexOf(next)==-1){
        if(fails){
          fails("未设置办理人")
        }else{
          ycWindow.dom.showMsg("未设置办理人", "error")
        }
        return false
      }
      debugger
      //查询出当前单据当前流程的所有待办任务
      const args = {
        "datatable_id": "1943259316018483200", // 数据源id
        "search_fields": [
          {
            "quick_search": true,
            "field": "jsrbh",
            "table": "a",
            "data_type": 1
          }
        ],
        "advance_filters": {condition: "a.:[glsjbh]=? and a.:[lc]=?", values: JSON.stringify([djid,dqlc])},
        "page": 1,
        "page_size": 999999,
        "include": {} 
      }
      ycWindow.plugins.crud.Query(args, (result2) => {
        debugger
        if(result2.total){
          result2.data.forEach((item,index) => {
            args1.steps.push({
              "step_name": "更新待办任务状态"+index,
              "opt_type": 4,
              "datatable_id": "1943259316018483200",
              "args": item.id,
              "args_from": 1,
              "field_params": [
                {
                  "value_from": 1,
                  "field": "zt",
                  "value": item.jsrbh==userid?"完成":"他人已办理",//判断是否是当前用户id，如果是则状态更新为完成，如果不是则为他人已办理
                  "data_type": 1
                }
              ]
            })
          });
        }
        debugger
        if(args1.steps.length){
          ycWindow.plugins.crud.ExecJobs(args1, (data) => {
              func()
            }, (data) => {
              if(fails){
                fails(data)
              }else{
                ycWindow.dom.showMsg(data, "error")
              }
          })
        }
      }, (data) => {
        if(fails){
          fails(data)
        }else{
          ycWindow.dom.showMsg(data, "error")
        }
      })
    }, (data) => {
      if(fails){
        fails(data)
      }else{
        ycWindow.dom.showMsg(data, "error")
      }
    })
  }
  //获取待办任务标题(办事处+项目+款项类型+款项金额)(xm项目，bsc办事处，fylx费用类型，je金额)
  function gzl_hqdbrwbt(xm,bsc,fylx,je,func){
    var mc=""
    var xmmc=""
    var bscmc=""
    var fylxmc=""
    if(xm!="非项目费用"){
        //获取项目名称
        ycWindow.plugins.crud.Get(xm, "1880859117036244992", (data1) => {
            xmmc=data1.mc
            //获取办事处名称
            ycWindow.plugins.crud.Get(bsc, "1880859114855206912", (data2) => {
                bscmc=data2.mc
                debugger
                //获取费用类型名称
                ycWindow.plugins.crud.Get(fylx, "1883552951188852736", (data3) => {
                debugger
                    fylxmc=data3.lx2
                    mc=xmmc+"/"+bscmc+"/"+fylxmc+"/"+(parseFloat(je)?parseFloat(je).toFixed(2):0)+"元"
                    func(mc)
                }, (data) => {
                if(fails){
                    fails("费用类型不存在")
                }else{
                    ycWindow.dom.opener.dom.showMsg("费用类型不存在", "error")
                }
                })
            }, (data) => {
            if(fails){
                fails("办事处不存在")
            }else{
                ycWindow.dom.opener.dom.showMsg("办事处不存在", "error")
            }
            })
        }, (data) => {
        if(fails){
            fails("项目不存在")
        }else{
            ycWindow.dom.opener.dom.showMsg("项目不存在", "error")
        }
        })
    }else{
        xmmc="非项目费用"
        //获取办事处名称
        ycWindow.plugins.crud.Get(bsc, "1880859114855206912", (data2) => {
            bscmc=data2.mc
            debugger
            //获取费用类型名称
            ycWindow.plugins.crud.Get(fylx, "1883552951188852736", (data3) => {
            debugger
                fylxmc=data3.lx2
                mc=xmmc+"/"+bscmc+"/"+fylxmc+"/"+(parseFloat(je)?parseFloat(je).toFixed(2):0)+"元"
                func(mc)
            }, (data) => {
            if(fails){
                fails("费用类型不存在")
            }else{
                ycWindow.dom.opener.dom.showMsg("费用类型不存在", "error")
            }
            })
        }, (data) => {
        if(fails){
            fails("办事处不存在")
        }else{
            ycWindow.dom.opener.dom.showMsg("办事处不存在", "error")
        }
        })
    }
  }